package cn.micro.core.thread;

import com.alibaba.ttl.threadpool.TtlExecutors;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import java.util.concurrent.Executor;

public class TtlExecutorsPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Executor) {
            Executor executor = (Executor) bean;
            if (TtlExecutors.isTtlWrapper(executor)) {
                return executor;
            }
            return TtlExecutors.getTtlExecutor(executor);
        }
        return bean;
    }
}
